<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.user.dto.RegisterUserQueryDTO"%>
<%@page import="com.sinba.common.user.service.IRegisterUserService"%>
<%@page import="com.sinba.common.user.dto.AccountDTO"%>
<%@page import="com.sinba.common.user.service.IAccountService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/declarationCenter.jsp");
	return;
}
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
IRegisterUserService registerUserService = (IRegisterUserService)ac.getBean("registerUserService");
RegisterUserQueryDTO qdto = new RegisterUserQueryDTO();
//registerUser!findDirectPushUserPager.action?registerUserQueryDTO.loginName=${session.loginName}&sord=desc&sidx=status
qdto.setDeclarationCenters((String)session.getAttribute("loginName"));
int pages = 1;
String sidx = "status";
String sord="desc";
if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
	pages = Integer.parseInt(request.getParameter("pages"));
}
int rows = 10;
int start = ( pages - 1 ) * rows;
qdto.setStart( start );
qdto.setLimit( rows );
PageDTO pageDTO = registerUserService.findRegisterUserPager(qdto, sord, sidx);
if(pageDTO!=null){
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
}
request.setAttribute("pageDTO",pageDTO);

//我推荐已激活
Integer dcActiveQuy = registerUserService.userCount((String)session.getAttribute("loginName"),"DeclarationCenterActivation",null);
request.setAttribute("dcActiveQuy",dcActiveQuy);

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><fmt:message key="i18n.operateCenter"/>-<fmt:message key="i18n.title"/> </title>
<link rel="shortcut icon" href="../index/favicon.png" />
<link href="../skin/skin1/css/subPage.css" rel="stylesheet">
<link rel="stylesheet" href="css/sub_page_main_style.css" />
</head>
<body style="background:#fff;height:800px;">
<div class="account">
	<div class="top"><fmt:message key="i18n.yewuManage"/> &gt; <fmt:message key="i18n.operateCenter"/>&nbsp;&nbsp;
		(<fmt:message key="i18n.zong"/>：${pageDTO.totalSize }，<fmt:message key="i18n.weijihua"/>：${pageDTO.totalSize-dcActiveQuy}，<fmt:message key="i18n.yijihua"/>：${dcActiveQuy })
	</div>
	<!-- <div class="left"></div> -->
    <div class="right" >
    	<table width="100%" border="0" cellspacing="0" cellpadding="0" id="smpl_tbl">
        		<thead>
        			<tr class="ltt">
        				<th><fmt:message key="i18n.xuhao"/></th>
        				<th><fmt:message key="i18n.userbianhao"/></th>
        				<th><fmt:message key="i18n.piUserName"/></th>
        				<th><fmt:message key="i18n.userlevel"/></th>
        				<th><fmt:message key="title.touZhiMoney" /></th>
        				<th><fmt:message key="i18n.regTime"/></th>
        				<th><fmt:message key="i18n.recommendUserId"/></th>
        				<th><fmt:message key="i18n.operation"/></th>
        			</tr>
        		</thead>
        		<tbody>
        			<c:forEach items="${pageDTO.data}" var="data" varStatus="in">
        				<tr>
        					<td>${in.count }</td>
        					<td>${data.loginName}</td>
        					<td>${data.userName}</td>
        					<td><fmt:message key="${data.registerLevel}" /></td>
        					<td>${data.registerMoney}</td>
        					<td><fmt:formatDate value="${data.registerTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
        					<td>${data.recommendUser}</td>
        					<td>
        						<c:if test="${data.status eq 'Activation'}"><fmt:message key="i18n.yijihua"/></c:if>
        						<c:if test="${data.status ne 'Activation'}">
        						<a id="acuser_${data.loginName}" href="javascript:accountActivate('${data.loginName}');">[<fmt:message key="i18n.clickJihuo"/>]</a><a href="javascript:delateRegister('${data.loginName}');">[<fmt:message key="i18n.delete"/>]</a></c:if>
        						
        					</td>
        				</tr>
        			</c:forEach>
        			<c:if test="${empty pageDTO.data}">
        				<tr>
        					<td colspan="8" align="center"><fmt:message key="i18n.noData"/>!</td>
        				</tr>
        			</c:if>
        		</tbody>		        		
        	</table>
        	<div class="page">
        	<div id="tr_recommendGrid_pager" class="page_r">
        		 <ul>
	        		<li><a href="declarationCenter.jsp?pages=1"><fmt:message key="i18n.firstPage"/></a></li>
	        		<c:if test="${pageDTO.page!=1}">
	        			<li><a href="declarationCenter.jsp?pages=${pageDTO.page-1}"><fmt:message key="i18n.upPage"/></a></li>
	        		</c:if>
	        		<li><a>${pageDTO.page}/${pageDTO.total}</a></li>
	        		<c:if test="${pageDTO.page+1<=pageDTO.total}">
	        			<li><a href="declarationCenter.jsp?pages=${pageDTO.page+1}"><fmt:message key="i18n.nextPage"/></a></li>
	        		</c:if>
	        		<li><a href="declarationCenter.jsp?pages=${pageDTO.total}"><fmt:message key="i18n.endPage"/></a></li>
	        		<li><a><fmt:message key="i18n.total"/>${pageDTO.totalSize}<fmt:message key="i18n.tiao"/></a></li>
        		</ul>
        	</div>
        	</div>
        	
        	<form  action="registerUser!userOpt.action" method="post" id="userActivate_form" ></form>
        	<form  action="registerUser!userOpt.action" method="post" id="deleteReguser_form" ></form>
    </div>
</div>
<script type="text/javascript" src="../scripts/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../scripts/user/common.js"></script>

<script type="text/javascript">
var isclick=true;
function accountActivate(loginName){
	
	$('#userActivate_form').html("<input type='hidden' name='pageUrl' value='declarationCenter.jsp' />"+
			"<input type='hidden' name='optType' value='userActive' />"+
			"<input type='hidden' name='activeType' value='DeclarationCenters' />"+
			"<input type='hidden' name='registerUserDTO.loginName' value='"+loginName+"' />");
	if(confirm('Are you sure you want to activate(是否确定要激活)?')){
		$('#acuser_'+loginName).attr("disabled",true);
		if(isclick){
			isclick=false;
			$('#userActivate_form').submit();
		}else{
			alert('操作过于频繁，请稍后再操作!');
		}
		
	}
}
function delateRegister(loginName){
	$('#deleteReguser_form').html("<input type='hidden' name='pageUrl' value='declarationCenter.jsp' />"+
			"<input type='hidden' name='registerUserDTO.loginName' value='"+loginName+"' />");
	if(confirm('Are you sure you want to delete(是否确定要删除)?')){
		$('#deleteReguser_form').submit();
	}
}
</script>

</body>
</html>